﻿using System;
using fastCSharp;

namespace diantou.web.management
{
    /// <summary>
    /// 编辑问题
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPage = false, IsPool = true)]
    partial class problemEdit : permissionView<problemEdit>
    {
        /// <summary>
        /// 测试类型集合
        /// </summary>
        private string[] judgeTypes = diantou.dataAccess.problem.JudgeTypes;
        /// <summary>
        /// 问题
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        private diantou.dataAccess.problem problem;
        /// <summary>
        /// 分组集合
        /// </summary>
        private diantou.dataAccess.problemGroup[] groups
        {
            get
            {
                if (diantou.dataAccess.clientCache.ProblemGroup.IsData) return diantou.dataAccess.clientCache.ProblemGroup.CacheValues.getArray();
                return diantou.dataAccess.tcpCall.problemGroup.getCache();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="problemId"></param>
        /// <returns></returns>
        private bool loadView(int problemId)
        {
            if ((currentUser.Permission & dataModel.user.permission.OnlineJudgeEditor) != 0)
            {
                if (problemId == 0)
                {
                    problem = diantou.dataAccess.problem.NullProblem;
                    return true;
                }
                if ((problem = diantou.dataAccess.clientCache.Problem[problemId]) != null)
                {
                    if (currentUser.Permission == dataModel.user.permission.Admin || problem.UserId == currentUser.Id) return true;
                    problem = null;
                }
            }
            AjaxResponse(new fastCSharp.code.cSharp.webView.errorPath { ErrorPath = currentUser.Path.NewFocus });
            return false;
        }
    }
}
